package cn.gorit.system.service.impl;

import cn.gorit.common.exception.SystemException;
import cn.gorit.dto.system.LinkDto;
import cn.gorit.entity.system.Link;
import cn.gorit.mapper.system.LinkMapper;
import cn.gorit.system.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version v1.0
 * @Classname LinkServiceImpl
 * @Description TODO
 * @Author CodingGorit
 * @Created on 2021/4/10 22:02
 * @IDLE IntelliJ IDEA
 **/
@Service
public class LinkServiceImpl implements LinkService {
    @Autowired
    private LinkMapper mapper;

    /**
     * 添加
     *
     * @param link
     */
    @Override
    public void save(LinkDto link) {
        mapper.saveLink(link);
    }

    /**
     * 修改
     *
     * @param link
     */
    @Override
    public void update(Link link) {
        if (link.getVersion() != null)
            mapper.updateLink(link);
        throw new SystemException("缺少 version 字段，修改失败");
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Override
    public Link getById(Integer id) {
        Link link = mapper.getLinkById(id);
        return link;
    }

    /**
     * 查询所有
     *
     * @return
     */
    @Override
    public List<Link> getAll() {
        List<Link> list = mapper.getAllLink();
        return list;
    }

    /**
     * 根据id删除
     *
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        mapper.deleteLinkById(id);
    }

    @Override
    public List<LinkDto> getLinkDtoList() {
        return mapper.getLinkDtoList();
    }
}
